#include <iostream>
#include <algorithm>
#include <deque>

using namespace std;

struct tmp
{
    tmp(int tx = 0, int ty = 0)
        :x(tx)
         ,y(ty)
    {}
    int x;
    int y;

};

ostream& operator << (ostream &os, const tmp &hs)
{
    os << "(" << hs.x << ", "
        << hs.y << ")";

    return os;
}

bool tmpCmp(const tmp &lhs, const tmp &rhs)
{
    if (lhs.x != rhs.x)
    {
        return lhs.x < rhs.x;
    }

    return lhs.y < rhs.y;
}

void test()
{
    deque<tmp> qt;
    qt.push_back(tmp(2, 2));
    qt.push_back(tmp(3, 1));
    qt.push_back(tmp(1, 3));
    qt.push_back(tmp(2, 3));

    for (auto t : qt)
    {
        cout << t;
    }
    cout << endl;

    cout << "-----------------------" << endl;

    std::sort(qt.begin(), qt.end(), tmpCmp);
    for (auto t : qt)
    {
        cout << t;
    }
    cout << endl;
}

void test1()
{
    deque<tmp> qt;
    qt.push_back(tmp(2, 2));
    qt.push_back(tmp(3, 1));
    qt.push_back(tmp(1, 3));
    qt.push_back(tmp(2, 3));

    for (auto t : qt)
    {
        cout << t;
    }
    cout << endl;

    cout << "-----------------------" << endl;

    std::sort(qt.begin(), qt.end(),
            [] (const tmp &lhs, const tmp &rhs)
            {
                if (lhs.x != rhs.x)
                {
                    return lhs.x < rhs.x;
                }
                return lhs.y < rhs.y;
            });
    for (auto t : qt)
    {
        cout << t;
    }
    cout << endl;
}

int main(int argc, char *argv[])
{
    test1();

    return 0;
}
